package com.oto.web.resource;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;


import org.springframework.beans.factory.annotation.Autowired;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.oto.service.AccountService;
import com.oto.service.FlowService;
import com.oto.service.PackService;
import com.oto.service.SharedDataService;

/**
 * @author xueqiang.mi
 * @since 2010-11-28
 */
public abstract class BaseResource {

	@Autowired
	protected AccountService accountService;
	@Autowired
	protected FlowService flowService;
	@Autowired
	protected PackService packService;
	@Autowired
	protected SharedDataService sharedDataService;

	@Context
	protected HttpServletRequest request;

	protected UserService userService;

	public BaseResource() {
		userService = UserServiceFactory.getUserService();
	}

	public String getUserName() {
		User user = userService.getCurrentUser();
		if (user == null) {
			return null;
		}

		accountService.add(user.getEmail(), "google.com");
		return user.getEmail();
	}
}
